<template>
  <!--
  正则校验：
    /[^\d.]/g           只能是数字，可以是小数
    /^(0+)|[^\d]+/g     只能是正整数

  -->
  <div class="config_eth_oam_ctp">
    <div style="background-color: #FFFFFF;position: absolute;    left: 280px;top: 18px;padding: 0px 10px">
      <p style="font-size: 18px"><b>ETH OAM 配置</b></p>
    </div>
<!--    <el-header class="header_oam">ETH OAM 配置</el-header>-->
    <el-form :model="ethOAM['oam-config']" :rules="rules" ref="ruleForm" label-width="120px" class="config_form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="MEP ID" prop="mep-id">
            <el-input v-model="ethOAM['oam-config']['mep-id']" clearable
                      placeholder="取值范围 1-8191" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')">
            </el-input>
          </el-form-item>
          <el-form-item label="远端MEP ID" prop="remote-mep-id">
            <el-input v-model="ethOAM['oam-config']['remote-mep-id']" clearable
                      placeholder="取值范围 1-8191" oninput="value=value.replace(/[^\d.]/g,'')">
            </el-input>
            <!--        <el-select v-model="ethOAM['oam-config']['remote-mep-id']" clearable placeholder="请选择源CTP">
                      <el-option label="CTP=1/2" value="shanghai"></el-option>
                      <el-option label="CTP=2/3" value="beijing"></el-option>
                    </el-select>-->
          </el-form-item>
          <el-form-item label="MEG ID" prop="meg-id">
            <el-input v-model="ethOAM['oam-config']['meg-id']" clearable
                      placeholder="取值范围 1-8191">
            </el-input>
          </el-form-item>
          <el-form-item label="mel" prop="mel">
            <el-select v-model="ethOAM['oam-config'].mel" clearable placeholder="请选择">
              <el-option value="1"></el-option>
              <el-option value="2"></el-option>
              <el-option value="3"></el-option>
              <el-option value="4"></el-option>
              <el-option value="5"></el-option>
              <el-option value="6"></el-option>
              <el-option value="7"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="CV帧发送周期" prop="cc-interval">
            <el-select v-model="ethOAM['oam-config']['cc-interval']" clearable
                       placeholder="请选择CV帧发送周期">
              <el-option
                  v-for="(i,index) in OamTransmitInterval"
                  :key="index"
                  :value="i">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="LM帧发送周期" prop="lm-interval">
            <el-select v-model="ethOAM['oam-config']['lm-interval']" clearable
                       placeholder="请选择LM帧发送周期">
              <el-option value="4"></el-option>
              <el-option value="5"></el-option>
              <el-option value="6"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="DM帧发送周期" prop="dm-interval">
            <el-select v-model="ethOAM['oam-config']['dm-interval']" clearable
                       placeholder="请选择DM帧发送周期">
              <el-option value="4"></el-option>
              <el-option value="5"></el-option>
              <el-option value="6"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <div style="float: left">
              <el-image
                  style="width: 20px; height: 25px;"
                  :src="require('@/assets/union_rule_font.jpg')"
                  :preview-src-list="[require('@/assets/union/ethOamConfig.jpg')]">
              </el-image>
              <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-row>



    </el-form>
  </div>
</template>

<script>
export default {
  name: "EthOAM",
  data() {
    return {
      rules: {
        'mep-id': [
          {required: true, message: '请输入mep-id', trigger: 'blur'}
        ],
        'remote-mep-id': [
          {required: true, message: '请输入remote-mep-id', trigger: 'blur'}
        ],
        'meg-id': [
          {required: true, message: '请输入meg-id', trigger: 'blur'},
        ],
        'md-name': [
          {required: true, message: '请输入md-name', trigger: 'blur'},
        ],
        'mel': [
          {required: true, message: '请输入mel', trigger: 'blur'},
        ],
        'cc-interval': [
          {required: true, message: '请选择周期', trigger: 'change'},
        ],
        'lm-interval': [
          {required: true, message: '请选择周期', trigger: 'change'},
        ],
        'dm-interval': [
          {required: true, message: '请选择周期', trigger: 'change'},
        ],

      },
      ethOAM: {
        "oam-config": {
          "mep-id": "0",
          "remote-mep-id": "0",
          "meg-id": "1",
          "md-name": "s",
          "mel": "4",
          "cc-interval": "2",
          "lm-interval": "2",
          "dm-interval": "4"
        }
      },
      OamTransmitInterval: [1, 2, 3, 4, 5, 6],

    }

  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style>
.config_eth_oam_ctp {
  width: 700px;
  height: auto;
  float: left;
  border: #a8a7a7 2px solid;
  border-radius: 20px;
  padding-top: 20px;
  margin-left: 50px;
  margin-top: 50px;
}

.header_oam {
  background-color: #a8a7a7;
  border-radius: 17px 17px 0px 0px;
  line-height: 35px;
  height: 40px !important;
}
</style>